<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>日期类型</title>
    <script>
        function f1(){
            let date = new Date();
            console.log(date);
            let year = date.getFullYear();
            let month = date.getMonth()+1;
            let day = date.getDate();
            let hour = date.getHours();
            let minute = date.getMinutes();
            let second = date.getSeconds();
            let week = date.getDay();
            console.log(year+"年"+month+"月"+day+"日 "+hour+":"+minute+":"+second+":"+date.getMilliseconds()+",星期"+week);
        }
        function f2(){
            // 在赋值时,参数是按照年、月、日、时、分、秒、毫秒设置的
            // 至少传递两个参数
            // 其他未传递参数的部分的值均为初始值
            // let date = new Date(2023,2);
            let date = new Date(2023,2,2,2,2,2,2);

            let year = date.getFullYear();
            let month = date.getMonth()+1;
            let day = date.getDate();
            let hour = date.getHours();
            let minute = date.getMinutes();
            let second = date.getSeconds();
            let week = date.getDay();
            console.log(year+"年"+month+"月"+day+"日 "+hour+":"+minute+":"+second+":"+date.getMilliseconds()+",星期"+week);
        }
        function f3(){
            let d = new Date(2020,12,31);
            d.setYear(2000);
            d.setMonth(1);
            let a = d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate();
            console.log(a);
            // A.2000-1-31  B.2000-2-2  C.2000-2-29 D.2000-3-2
        }
    </script>
</head>
<body>
<button onclick="f1()">获取当前时间</button><br>
<button onclick="f2()">设置指定日期</button><br>
<button onclick="f3()">练习</button><br>

</body>
</html>